<extend name="Public/layout"/>
<block name="head">
<link rel="stylesheet" href="__PUBLIC__css/get-cash.css">
<style type="text/css">
.footer{
    display: none;
}
</style>
</block>
<block name="main">

    <div class="bankcard">
        <div class="bankcard-wrapper">
            <!----------注意：下面银行卡分别做了区分的------------>
            <div class="bankcard-top">
                <span class="bank-icon  bank-default"></span>
                <span class="bank-text">已绑定银行卡</span>
            </div>
           
            <div class="bankcard-bottom">
                <span>****</span>
                <span>****</span>
                <span>****</span>
                <span>{$user_info.bank_card_small}</span>
            </div>
        </div>
    </div>
    <div class="content">
        <div class="total-cash-wrapper">
            <div class="left">可提现余额</div>
            <if condition="$val eq 1">
            <div class="right">{$user_info.balance}</div>
            <else/>
            <div class="right">{$user_info.prize_balance}</div>
            </if>
        </div>
        <div class="get-cash-wrapper">
            <p class="text">提现金额</p>
            <div class="input">
                <input type="text" name="cash_val" placeholder="请输入您的提现金额">
            </div>
            <p>剩余免费提现次数：<span class="count">1</span>次</p>
        </div>
        <div class="btn-wrapper">
            <a href="#" class="get-cash-btn" onclick="getCash()">申请提现</a>
        </div>
        <!--提现说明-->
        <div class="defined-text-wrapper">
            <a href="/Home/Person/cash_explain">提现说明</a>
        </div>
    </div>

</block>

<block name="js">
    <script>
    var charge ='';
    function getCash() {
        var cash_val = parseFloat($('input[name="cash_val"]').val());
        //获取手续费
        if (cash_val == '' || cash_val == undefined || cash_val == null) {
            layer.closeAll();
            layer.open({
                content: '请输入提现金额'
                ,skin: 'msg'
                ,time: 2
            });
            return
        }

        if (!/^\d+$/.test(cash_val)) {
            layer.closeAll();
            layer.open({
                content: '提现金额只能是数字'
                ,skin: 'msg'
                ,time: 2
            });
            $('input[name="cash_val"]').val('')
            return
        }
         
         var id = '{$_SESSION["user"]["id"]}'
        $.post('/Home/Person/get_charge',{
            id:id,
        },function(res){
            if(res.err==1){
                 charge=1;
            }else{
                 charge='0.00';
            }
            var h = '';
            h += '<div class="get-cash-layer">'
            h += '<div class="content-wrapper"><h3 class="header">提现确认</h3>'
            h += '<p class="text">提现金额：'+cash_val+'元</p>'
            h += '<p class="text">提现手续费：'+charge+'元</p>'
            h += '<p class="text">到账时间：您的提现将在T+1日后到账</p></div>'
            h += '<div class="btn-wrapper"><a href="javascript:" onclick="layer.closeAll()">取消</a>'
            h += '<a href="javascript:" onclick="withdrawals()">确认</a></div>'
            h += '</div>'

            // 提现弹框
            layer.open({
                type: 1
                ,area: ['280px', '197px']
                ,content: h
            });
        })
        
    }

    //确认提现
function withdrawals() {
    var affirmdepo = $('input[name="cash_val"]').val();
    var val = "{$_GET['val']}"
    if (!isNaN(affirmdepo)) {
        $.post('/Home/Person/withdrawals', {
            affirmdepo: affirmdepo,
            type:val
        }, function (res) {
             
            if (res.err == 0) {
                layer.open({
                    content:res.msg
                    ,skin: 'msg'
                    ,time: 2
                    ,end:function(){
                        location.href="/Home/Person/cash_success/val/"+val
                        
                    }
                });
            }else{
                layer.open({
                    content:res.msg
                    ,skin: 'msg'
                    ,time: 2
                    ,end:function(){
                         layer.closeAll();
                    }
                });
            }
        });
    } else {
        layer.open({
            content:"请输入正确的提现金额"
            ,skin: 'msg'
            ,time: 1 //2秒后自动关闭
          });
    }
}


    </script>    
</block>